package com.copa.gamestore.module.cart.controller;

import com.copa.gamestore.common.response.ResponseVo;
import com.copa.gamestore.module.cart.application.CartApplicationService;
import com.copa.gamestore.module.cart.dto.CartDto;
import com.copa.gamestore.module.cart.vo.CartVo;
import com.copa.gamestore.security.domain.Role;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.RolesAllowed;
import java.util.List;

/**
 * @author copa
 * @createDate 2022-09-27 11:26
 * @function
 */
@RestController
@RequestMapping("cart")
@Api(tags = "购物车服务")
public class CartController {

    @Resource
    private CartApplicationService cartApplicationService;

    @ApiOperation("添加/修改购物车")
    @RolesAllowed(Role.USER)
    @PostMapping
    public ResponseVo<String> post(@RequestBody @Validated CartDto cartDto) {
        return cartApplicationService.post(cartDto);
    }

    @ApiOperation("获取购物车信息")
    @RolesAllowed(Role.USER)
    @GetMapping
    public ResponseVo<CartVo> get() {
        return cartApplicationService.get();
    }

    @ApiOperation("删除购物车信息")
    @RolesAllowed(Role.USER)
    @DeleteMapping
    public ResponseVo<String> delete(@RequestBody List<Long> ids) {
        return cartApplicationService.delete(ids);
    }
}
